#ifndef __WP_MODEL_H__
#define __WP_MODEL_H__
#include <vector>
#include "SQLiteWrapper.h"


class IWPViewModel
{
public:
    virtual void UpdateMaterialsView(LPCTSTR lpszName) = 0;

    virtual void UpdateGradesView(LPCTSTR lpszName) = 0;

    virtual void UpdateUnitsView(LPCTSTR lpszName) = 0;
};

typedef struct {
    int  nId;
    TCHAR szName[64];
} TLevelItem;

typedef struct  
{
    TCHAR szType[8];
    TCHAR szTypeName[16];
    TCHAR szEnSimpleSentence[256];
    TCHAR szZnSimpleSentence[128];
} TSSentItem;

typedef struct  
{
    int nIsSub;
    TCHAR szType[8];
    TCHAR szTypeName[32];
    TCHAR szSubTypeName[32];
    TCHAR szSubContent[64];
    TCHAR szEnCommonSentence[256];
    TCHAR szZnCommonSentence[128];
} TSCommonItem;

typedef struct  
{
    TCHAR szType[8];
    TCHAR szMeaning[64];
} TWordMeaningItem;

typedef struct 
{
    TCHAR szType[8];
    TCHAR szTypeName[16];
    TCHAR szContent[512];
} TWordUsageItem;

typedef struct  
{
    int bChecked;
    int nWordId;
    int nUnitId;
    TCHAR szWord[64];
    TCHAR szWordMeaning[64];
    TCHAR szEnSymbol[64];
    TCHAR szUsSymbol[64];
    TCHAR szFenjie[96]; 
    std::vector<TSSentItem> vectSSents;
    std::vector<TWordMeaningItem> vectWordMeanings;
    std::vector<TSCommonItem> vectSCommons;
    std::vector<TWordUsageItem> vectWordUsage;
} TUnitWord;

//Between Chinese and English
typedef struct  
{
    TUnitWord* pUnitWord;
    int nMode;//En->CH:0 or CH->EN:1
    int nAnswer;
    int nChAnswer;
    int nEnAnswer;
    int nSpendTime;
    std::vector<TUnitWord*> vectOptions;
    std::vector<CDuiString> vectChExerOpts;
    std::vector<CDuiString> vectEnExerOpts;
    std::vector<CDuiString> vectExerOptions;
    int nIsAnswerRight; //0:Error 1:right
    TCHAR szUserAnswer[64];
} TExerEn2Ch;

typedef struct 
{
    int nSpendTime;
    TCHAR szStudyTime[32];
    TCHAR szUnitDesc[256];
    std::vector<TUnitWord> vectTotalWords;
    std::vector<TUnitWord> vectNewWords;
} TStudyRecord;

class CWPModel
{
public:
    CWPModel(void);

    CWPModel(UINT nTrainMode, IWPViewModel* pWnd);

    ~CWPModel(void);

    typedef enum {
        E_TYPE_TRAIN_PREVIEW,
        E_TYPE_TRAIN_REVIEW,
    } TRAINTYPE;

public:

    BOOL Load();

    void SetView(IWPViewModel* pWnd);

    void GetAllLevelItem();

    void GetMaterialsByLevel(LPCTSTR lpszLevelName);

    UINT GetTrainMode();

    UINT GetReviewMode();

    void SetReviewMode(int nReviewMode);

    void GetGradesByMaterial(LPCTSTR lpszMaterial);

    void GetUnitsByGrade(LPCTSTR lpszGrade);

    int GetWordCountByUnit(LPCTSTR lpUnit);

    int GetWordsByUnit(LPCTSTR lpUnit);
    
    int GetSimpleSentencesOfWord(TUnitWord* pUnitWord);

    int GetSelectWords(std::vector<TUnitWord*> &selectWords);

    int GetWordMeaning(TUnitWord* pUnitWord);
   
    int GetCommonSentencesOfWord(TUnitWord* pUnitWord);

    int GetWordUsage(TUnitWord* pUnitWord);

    int GetNineWords(TUnitWord* pUnitWord, std::vector<TUnitWord*> &nineWords);

    int GetExerEn2Ch(TExerEn2Ch& exItem);

    int AddNewWord(TUnitWord* pUnitWord);

    int DeleteNewWord(TUnitWord* pUnitWord);

    int GetNewWords();

    int GetStudyRecords();
    
    int GetStudyRecordsEx();

    int AddStudyRecords(TExerEn2Ch& exItem);

    int UpdateUnitWords(std::vector<TUnitWord>& vectWords);

    int GetUnitInfo(int nUnitId, CDuiString &strUnit, CDuiString &strSems, CDuiString &strVer);

public:
    SQLiteWrapper m_db; 

public:
    std::vector<TLevelItem> m_vectLevel;

    IWPViewModel *m_pViewModel;

    UINT m_nTrainMode;

    UINT m_nReviewMode;


    std::vector<TUnitWord> m_vectWords;

    std::vector<TUnitWord> m_vectNineWords;
    
    std::vector<TStudyRecord> m_vectStudyRecords;
    TStudyRecord* m_ptSR;
};
#endif